package com.changeover.gwt.client.controller;

import com.changeover.gwt.client.event.LoginEvent;
import com.changeover.gwt.client.view.ICustomerDetails;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.shared.HandlerManager;
import com.google.gwt.user.client.ui.HasWidgets;

public class CustomerDetailsController implements Controller {
    
    private final ICustomerDetails view;
    private final HandlerManager eventBus;
    
    public CustomerDetailsController(HandlerManager eventBus, ICustomerDetails view) {
        this.eventBus = eventBus;
        this.view = view;
    }
    
    @Override
    public void go(HasWidgets container) {
        bind();
        container.clear();
        container.add(view.asWidget());
    }
    
    private void bind() {
        view.getCloseButton().addClickHandler(new ClickHandler() {
            @Override
            public void onClick(ClickEvent event) {
                eventBus.fireEvent(new LoginEvent());
            }
        });
    }
}
